package org.example.day20240815;

import java.util.Random;

public class MyMath {
    public static int abs(int x){
        if(x<0){
            return -1*x;
        }else{
            return x;
        }
    }

    public static double pow(int x, int y){
        int result = 0;
        for(int i = 0; i<=y; i++){
            result += 1*x;
        }
        return result;
    }

    public static int max(int[]x){
        int result = 1;
        for(int i =0; i<=x.length; i++){
            if(x[i]>x[i+1]){
                result = x[i];
            }
        }
        return result;
    }

    public static int min(int[]x){
        int result = 1;
        for(int i =0; i<=x.length; i++){
            if(x[i]<x[i+1]){
                result = x[i];
            }
        }
        return result;
    }

    public static int floor(double x){
        return (int)x;
    }

    public static char getRandomChar(){
        //数字或大小写字母
        Random random = new Random();
        while (true){
            int tmp = random.nextInt(123);
            if((tmp >= 48 && tmp <= 57)
                    || (tmp >= 65 && tmp <= 90)
                    || (tmp >= 97 && tmp <= 122)){
                return (char)tmp;
            }
        }
    }
}

